#include "StdAfx.h"
#include "UserInfo.h"
inline BOOL SetStringT(TCHAR * dst,const TCHAR* src,INT nMaxLen)
{
	INT nSrcLen = _tcslen(src);
	if (MSUTIL::IsNull((PVOID)src) || nSrcLen > nMaxLen)
	{
		return FALSE;
	}
	_tcscpy(dst,src);
	dst[nSrcLen] = 0;
	return TRUE;
}
CUserInfo::CUserInfo(const CUserInfo & otherUserInfo)
{
	CopyFrom(otherUserInfo);
}
const CUserInfo& CUserInfo::operator=(const CUserInfo& otherUserInfo)
{
	CopyFrom(otherUserInfo);
	return *this;
}
VOID CUserInfo::CopyFrom(const CUserInfo &otherUserInfo)
{
	CUserInfo * tmpUserInfo = (CUserInfo *)&otherUserInfo;
	m_bGender = tmpUserInfo->GetGender();
	m_bOnLine = tmpUserInfo->GetOnLine();
	
	_tcscpy(m_szHost,tmpUserInfo->GetHostName());
	m_szHost[_tcslen(tmpUserInfo->GetHostName())] = 0;
	_tcscpy(m_szGroup,tmpUserInfo->GetGroup());
	m_szGroup[_tcslen(tmpUserInfo->GetGroup())] = 0;
	strcpy(m_szIP,tmpUserInfo->GetIPAddress());
	m_szIP[strlen(tmpUserInfo->GetIPAddress())] = 0;
	_tcscpy(m_szNickName,tmpUserInfo->GetNickName());
	m_szNickName[_tcslen(tmpUserInfo->GetNickName())] = 0;
}
CUserInfo::CUserInfo(void):
m_bGender(TRUE),
m_bOnLine(TRUE)
{
	ZeroMemory(m_szHost,MAX_HOST_LEN+2);
	ZeroMemory(m_szIP,MAX_IP_LEN+2);
	ZeroMemory(m_szGroup,MAX_GROUP_LEN+2);
	ZeroMemory(m_szNickName,MAX_NICK_NAME_LEN+2);
}

CUserInfo::~CUserInfo(void)
{
}
BOOL CUserInfo::SetNickName(const TCHAR* szNickName)
{
	return SetStringT(m_szNickName,szNickName,MAX_NICK_NAME_LEN);
}
BOOL CUserInfo::SetHostName(const TCHAR* szHostName)
{
	return SetStringT(m_szHost,szHostName,MAX_HOST_LEN);
}
BOOL CUserInfo::SetIPAddress(const CHAR* szIPAddress)
{
	INT nSrcLen = strlen(szIPAddress);
	if (MSUTIL::IsNull((PVOID)szIPAddress) || nSrcLen > MAX_IP_LEN)
	{
		return FALSE;
	}
	strcpy(m_szIP,szIPAddress);
	m_szIP[nSrcLen] = 0;
	return TRUE;
}
BOOL CUserInfo::SetGroup(const TCHAR* szGroup)
{
	return SetStringT(m_szGroup,szGroup,MAX_GROUP_LEN);
}
